<!DOCTYPE html>
<html>
<head>
	<title>添加新版本</title>
	<!--#include("../common/common-link.html"){}-->
	<script src="${ctx}/assets/js/fileupload.js"></script>
	<style type="text/css">
		.layui-form-switch{margin-top: 0;}
		.table-panel .content table{margin: 0 auto;margin-top: 10px;}
		.table-panel .content table tr{height: 49px;}
		.table-panel .content table tr.btns td .btn{width: 123px;outline: none;margin-top:20px;}
		.table-panel .content table tr td .need{color: red;}
		.table-panel .content table tr td.left{text-align: right;}
		.table-panel .content table tr td.right{text-align: left;}
		.table-panel .content table tr td.right .form-control{width:330px;}
		.table-panel .content table tr td.center{text-align: center;}
	</style>
</head>
<body>
	<div id="container-wrap" style="display:none;">
		<div class="table-panel">
			<div class="header">
				<h4 class="title">添加新版本</h4>
				<div class="btns-group">
					<input type="button" class="btn btn-primary" onclick="javascript:window.history.back()" value="返回"/>
				</div>
			</div>
			<div class="content">
				<table>
					<tr>
						<td class="left">外部版本：</td>
						<td class="right">
							<input class="form-control" :value="form.version" v-model="form.version">
						</td>
					</tr>
					<tr>
						<td class="left">内部版本：</td>
						<td class="right">
							<input class="form-control" :value="form.edition" v-model="form.edition">
						</td>
					</tr>
					<tr>
						<td class="left">系统：</td>
						<td class="right">
							<div class="layui-unselect layui-form-radio layui-form-radioed" v-if="form.osType==1">
						        <i class="layui-anim layui-icon layui-anim-scaleSpring">&#xe643;</i>
						        <span>Android</span>
						    </div>
						    <div class="layui-unselect layui-form-radio os-type-redio" data-type="1" v-else>
						        <i class="layui-anim layui-icon">&#xe63f;</i>
						        <span>Android</span>
						    </div>
						</td>
					</tr>
					<tr>
						<td class="left">终端：</td>
						<td class="right">
						    <div class="layui-unselect layui-form-radio layui-form-radioed" v-if="form.terminalType==1">
						        <i class="layui-anim layui-icon layui-anim-scaleSpring">&#xe643;</i>
						        <span>商户总店</span>
						    </div>
						    <div class="layui-unselect layui-form-radio terminal-type-redio" data-type="1" v-else>
						        <i class="layui-anim layui-icon">&#xe63f;</i>
						        <span>商户总店</span>
						    </div>
						    <div class="layui-unselect layui-form-radio layui-form-radioed" v-if="form.terminalType==4">
						        <i class="layui-anim layui-icon layui-anim-scaleSpring">&#xe643;</i>
						        <span>商户分店</span>
						    </div>
						    <div class="layui-unselect layui-form-radio terminal-type-redio" data-type="4" v-else>
						        <i class="layui-anim layui-icon">&#xe63f;</i>
						        <span>商户分店</span>
						    </div>
						</td>
					</tr>
					<tr>
						<td class="left">强制升级：</td>
						<td class="right">
							<div class="layui-form" v-if="form.forceUpgrade">
								<div id="switch" class="layui-unselect layui-form-switch layui-form-onswitch" lay-skin="_switch"><em>是</em><i></i></div>
							</div>
							<div class="layui-form" v-else>
								<div id="switch" class="layui-unselect layui-form-switch" lay-skin="_switch"><em>否</em><i></i></div>
							</div>
						</td>
					</tr>
					<tr>
						<td class="left">包文件：</td>
						<td class="right">
							<button type="button" class="layui-btn upload-btn" style="display: inline-block;">
						    	<i class="layui-icon">&#xe67c;</i>上传包文件
							</button>
							<span style="display: inline-block;">{{fileName}}</span>
							<input class="layui-upload-file upload-file" type="file" @change="fileChange($event)" style="display: none">
						</td>
					</tr>
					<tr>
						<td class="left">包链接：</td>
						<td class="right">
							<input class="form-control" :value="form.linkHref" v-model="form.linkHref">
						</td>
					</tr>
					<tr>
						<td class="left" style="vertical-align: top">更新内容：</td>
						<td class="right" style="vertical-align: top">
					    	<textarea name="desc" placeholder="请输入内容" class="layui-textarea" :value="form.content" v-model="form.content"></textarea>
						</td>
					</tr>
					<tr class="btns">
						<td class="center" colspan="2">
							<input type="button" class="btn btn-primary ok_btn" value="确定" @click="submit"/>
							<input type="button" class="btn btn-primary cancel_btn" value="取消" @click="cancel"/>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="hidden" style="display: none">
			<input type="file" class="uploader"/>
		</div>
	</div>
</body>
<script type="text/javascript">
	var data = {};
	var vue = {};
	var form={};
	vue.initialize = function() {
		form.version="";
		form.edition="";
		form.osType=1;
		form.terminalType=1;
		form.forceUpgrade=0;
		form.content="";
		form.linkHref="";
		data.fileName="";
		data.form = form;
		new Vue({
			el:"#container-wrap",
			data:data,
			methods:vue
		});
		Vue.nextTick(function() {
			bindEvent();
			initUploader();
			$("#container-wrap").show();
		});
		
	};
	function bindEvent(){
		$(".os-type-redio").click(processOsType);
		$(".terminal-type-redio").click(processTerminalType);
		$("#switch").click(processForceUpgrade);
		$(".upload-btn").click(function(){
			$(".upload-file").click();
		});
	};
	function initUploader(){
		fileList=[];
		uploader={};
		uploader.url="add";
		uploader.dataType="json";
		uploader.autoUpload=false;
		uploader.paramName="file";
		uploader.fail=function(event, data) {
        	layer.close(uploader.loadId);
            util.error("处理失败");
        };
        uploader.done=function(event, _result) {
        	layer.close(uploader.loadId);
            var result = _result.result;
            var status=result.status;
			var code=result.code;
			var errorMsg=result.errorMsg;
			if(status=='success'){
				cancel();
				return ;
			}else{
				util.error(errorMsg);
			}
        };
        $('.uploader').fileupload(uploader);
        uploader.submit=function(form){
        	var formData=util.checkInvalid(form.formData);
        	if(!form.files.length){
        		form.files=[""];
        	};
        	form.formData=formData;
        	uploader.loadId=util.load();
    		$('.uploader').fileupload('send',form);
        }
        return uploader;
	};
	function processOsType(e){
		var _osType=e.currentTarget.dataset.type;
		form.osType=_osType;
		Vue.nextTick(function() {
			$(".os-type-redio").click(processOsType);
		});
	};
	function processTerminalType(e){
		var _terminalType=e.currentTarget.dataset.type;
		form.terminalType=_terminalType;
		Vue.nextTick(function() {
			$(".terminal-type-redio").click(processTerminalType);
		});
	};
	function processForceUpgrade(){
		if(form.forceUpgrade){
			form.forceUpgrade=0;
		}else{
			form.forceUpgrade=1;
		}
		Vue.nextTick(function() {
			$("#switch").click(processForceUpgrade);
		});
	};
	function fileChange(e){
		var $file=$(e.target);
		data.fileName=$file.val();
		fileList.splice(0,fileList.length);
		fileList.push($file.prop('files')[0]);
	};
	function submit(){
		if($.trim(form.version)==''){
			util.warning("请填写外部版本号！");
			return ;
		}
		if($.trim(form.edition)==''){
			util.warning("请填写内部版本号！");
			return ;
		}
		if($.trim(form.linkHref)==''&&$.trim(data.fileName)==""){
			util.warning("包文件和包链接须选填一个！");
			return ;
		}
		if($.trim(form.linkHref)!=''&&$.trim(data.fileName)!=""){
			util.warning("包文件和包链接须选填一个！");
			return ;
		}
		loadId = util.load();
		var _data={};
		_data.formData=form;
		_data.files=fileList;
		uploader.submit(_data);
	};
	function cancel(){
		window.history.back();
	};
</script>
</html>